class Solution {
public:
    int getLongestPalindrome(string str) {
        // dp[i][j]表示以i为开头，j为结尾的最长回文子串长度
        int n = str.size();
        if (n == 1) return 1;
        int res = 1;
        vector<vector<bool>> dp(n, vector<bool>(n));
        for (int k = 0; k < n; ++k) {
            dp[k][k] = true;
        }
        for (int sz = 1; sz <= n; ++sz) {
            for (int i = 0; i <= n-sz; ++i) {
                int j = i+sz-1;
                if (str[i] == str[j]) {
                    if (sz <= 2) {
                        dp[i][j] = true;
                        res = sz;
                    } else {
                        dp[i][j] = dp[i+1][j-1];
                        if (dp[i][j]) {
                            res = sz;
                        }
                    }
                }      
            }
        }
        return res;
    }
}; 